//cp34.cxx


# define DEFINE_GLOBAL
#include "global.h"

#include "geom_pbc.h"

#include <Rtypes.h>
#include <iostream>
#include <cstdlib>
#include <random>
#include <vector>
#include <time.h> 
#include "lanczos.h"
#include "myvectormath.h"
using namespace std;



Int_t main ( Int_t argc, const char* argv[] ){
  
  // Prints each argument on the command line.
  for( int i = 0; i < argc; i++ )
  {
    cout << "arg " << i << ": " << argv[i] << endl;
  }
  
  int nsteps;
  if (argc==1){cout << "Call with \"cp32 ndim steps debugv\" \n MatDim = dimensions of the lattice \n steps= number of steps in every direction \n debugv = debug verbosity \n betaerror: default = 0" << endl;}
  if (argc>1){ndim=atoi(argv[1]);}else{ndim=2;}
  if (argc>2){nsteps=atoi(argv[2]);}else{nsteps=5;}
  if (argc>3){debug=atoi(argv[3]);}else{debug=0;}
  if (argc>4){betaerror=atof(argv[4])+1;}else{betaerror=1;}
  
  lsize=new int[ndim+1];
  lsize[0]=0;
  for (int i=1; i<=ndim;i++){
    lsize[i]=nsteps;
  }
  
  // Initialisierung der geometrie
  geom_pbc();
  cout << "Volumen: " << nvol << endl;
  
  
  
  // Generierung des Quellenvektors
  
  // generators for non-zero elements of matrix. for now only diagonal matrices are created and so the position is fixed.
  default_random_engine generator(time(NULL));
  uniform_real_distribution<Double_t> distributiond(0.0,1.0); // to generate the values
  // uniform_int_distribution<int> distributioni(1,fMatDim); // to generate the position of the nonzero elements
  
  mass=0.5;
  vector<Double_t> b(nvol);
  for( int i = 0; i < nvol; i++) {
//     b.at(i)= 2*distributiond(generator)-1;
    b.at(i)= 0.5*i;
  }
  if (debug>=3){ // print b
    cout << "b: ";
    for (auto it = b.cbegin(); it != b.cend(); ++it)
      std::cout << ' ' << *it;
    std::cout << '\n';
  }

  int result;
  result = lanczos(nvol,&b,Laplaceproduct);
  cout << result << endl;
  
  delete lsize;
  
  return 0;
}
